package com.shyt.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shyt.dao.SysPermissionVo;
import com.shyt.dao.SysUserVo;
import com.shyt.filter.annotation.RecordLogsAspectAt;
import com.shyt.impl.SysPermissionServiceImpl;
import com.shyt.impl.SysUserServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
@Slf4j
@CrossOrigin
public class T20230308Api {
//    public static void main(String[] args) {
//        //用户密码
//        String password = "123456";
//        //密码加密
//         BCryptPasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
//        //加密
//        String newPassword = passwordEncoder.encode(password);
//        System.out.println("加密密码为："+newPassword);
//        //对比这两个密码是否是同一个密码
//         boolean matches = passwordEncoder.matches(password, newPassword);
//         System.out.println("两个密码一致:"+matches);
//    }
    @Autowired
    SysUserServiceImpl sysUserServiceImpl;
    @Autowired
    SysPermissionServiceImpl sysPermissionServiceImpl;

    @RecordLogsAspectAt
    @GetMapping("/test1")
    public String testController() {
        log.info("进入到异常测试");
        return "调用成功";
    }

    /***
     * 测试异常
     * @return 返回统一封装信息
     */
    @RecordLogsAspectAt
    @GetMapping("/selectSysUsers")
    public IPage<SysUserVo> selectSysUsers() {
        IPage<SysUserVo> page = new Page(1,2);
        return sysUserServiceImpl.selectSysUsers(page);
    }


    /***
     * 测试异常
     * @return 返回统一封装信息
     */
    @RecordLogsAspectAt
    @PostMapping("/selectSysUserByUsername")
    public List<SysUserVo> selectSysUserByUsername(@RequestBody Map<String,String> username) {
        log.info("进入查询用户开始————————————————————");
        return sysUserServiceImpl.selectSysUserByUsername(username.get("username"));
    }

    /***
     * 测试异常
     * @return 返回统一封装信息
     */
    @RecordLogsAspectAt
    @PostMapping("/selectPermissions")
    public List<SysPermissionVo> selectPermissions(@RequestBody Map<String,String> rcMap) {
        return sysPermissionServiceImpl.selectPermissions(rcMap);
    }

}
